// Seir programming Editor
// Copyright (c) <2007> <David Torres>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

/*
 * Created by SharpDevelop.
 * User: David William Torres
 * Date: 5/29/2007
 * Time: 2:45 PM
 * 
 */

using System;
using System.IO;

namespace Seir
{
	public class sDocument
    {
        #region Variables

        private string s_strFileName;
		private bool s_bIsModified;
		private bool s_bIsNewDocument;
		private StreamReader s_sr = null;

        #endregion

        #region Getters and Setters

        // Stream reader
		public StreamReader TextStream
		{
			get
			{
				return s_sr;
			}
		}

		// Determines if the document is
		// newly created or pre-existing.
		public bool IsNewDocument
		{
			get
            {
                return s_bIsNewDocument;
            }
			set
            {
                s_bIsNewDocument = value;
            }
		}
		
		// Determines if the document is modified or not
		public bool IsModified
		{
			get
            {
                return s_bIsModified;
            }
			set
            {
                s_bIsModified = value;
            }
		}
		
		// File that contains the data
		public string FileName
		{
			get
            { 
                return s_strFileName;
            }
			set
            {
                s_strFileName = value;
            }
        }

        #endregion

        #region Constructor

        public sDocument()
		{
			s_bIsModified = false;
			s_bIsNewDocument = true;
			s_strFileName = "";
        }

        #endregion

        #region Save Document

        public void SaveDocument(string strFileName, string strContent)
		{
			StreamWriter sw = null;

			// Quick and dirty error checking
			if(strFileName.Length < 1 || strContent.Length < 1)
				return;

			try
			{
				sw = new StreamWriter(strFileName, false);
				sw.Write(strContent);
				sw.Close();
			}
			catch(Exception exc)
			{
				Console.WriteLine(exc.Message);
			}
        }

        #endregion

        #region Open Document

        public void OpenDocumentForRead(string strFileName)
		{
			try
			{
				s_sr = File.OpenText(strFileName);
				this.s_strFileName = strFileName;
			}
			catch(Exception exc)
			{
				throw exc;
			}
        }

        #endregion

    }
}
